package edu.cs.usask.ca.silver.plugin.rcp.dialogs.edit;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * A simple class that allows the displayed model object name to be changed by
 * the user This us generic for all editors opened in the RCP UI
 * 
 * @author Mike Taylor
 * 
 */
public class EditModelObjectNameDialog extends Dialog {

	private Text modelObjectNameText;
	private String modelObjectName;

	public EditModelObjectNameDialog(Shell parentShell, String objectName) {

		super(parentShell);
		modelObjectName = objectName;
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("Edit Model Object Name");
	}

	/**
	 * a method that creates the dialog box that allows the user to change any
	 * model object name This is generic for all info editors that are created
	 */
	@Override
	protected Control createDialogArea(Composite parent) {

		// TODO figure out how to set the size of this dialog box

		final Composite composite = new Composite(parent, SWT.NONE);
		GridLayout layout = new GridLayout(2, false);
		composite.setLayout(layout);

		Label modelObjectNameLabel = new Label(composite, SWT.NONE);
		modelObjectNameLabel.setText("&Model Object Name:");
		modelObjectNameLabel.setLayoutData(new GridData(GridData.END,
				GridData.CENTER, false, false));

		modelObjectNameText = new Text(composite, SWT.BORDER);
		modelObjectNameText.setLayoutData(new GridData(GridData.FILL,
				GridData.FILL, true, false));
		modelObjectNameText.setText(modelObjectName);

		return composite;

	}/* end of control method */

	@Override
	protected void okPressed() {
		modelObjectName = modelObjectNameText.getText();
		super.okPressed();
	}/* end of save method */

	public String getModelObjectName() {
		return modelObjectName;

	}/* end of get name method */

}/* end of the edit name dialog class */
